package model

import "fmt"

type Student struct {
	Name string
	Age  int32
	Id   int32
}

type Personal struct {
	Name string
	Age  int32
	Id   int32
}

func StructToMap(dataMap interface{}) interface{} {
	fmt.Printf("dataMap is %T\n",dataMap)
	switch dataMap.(type) {
	case Student:
		ToDate :=dataMap.(Student)
		return map[string]interface{}{
			"stu_name" : ToDate.Name,
			"stu_age" : ToDate.Age,
			"stu_id" : ToDate.Id,
			"tag" : "Student",
		}
	case Personal:
		ToDate :=dataMap.(Personal)
		return map[string]interface{}{
			"per_name" : ToDate.Name,
			"per_age" : ToDate.Age,
			"per_id" : ToDate.Id,
			"tag" : "Personal",
		}
	default:
		fmt.Println("传入类型错误")
		return nil
	}
}